package com.huawei.crm.web.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
 * 分页实体信息
 *
 * @param <T>
 * @author luohua
 * @date 2021年12月30日17:19:30
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageInfo<T> implements Serializable {

    private static final long serialVersionUID = 4763239924052986386L;

    /**
     * 数据结果集
     */
    private List<T> results;

    /**
     * 搜索到符合条件的结果总数
     */
    private Integer totalCount = 0;

    /**
     * 页码，默认值：1
     */
    private Integer pageNum = 1;

    /**
     * 每页条数，默认值：10
     */
    private Integer pageSize = 10;

    private PageInfo(List<T> results) {
        this.results = results;
    }

    private PageInfo(Integer pageNum, Integer pageSize) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
    }

    public static <T> PageInfo<T> of(List<T> results) {
        return new PageInfo<>(results);
    }

    public static <T> PageInfo<T> of(Integer pageNum, Integer pageSize) {
        return new PageInfo<>(pageNum, pageNum);
    }

    public static <T> PageInfo<T> of(List<T> results, Integer totalCount, Integer pageNum, Integer pageSize) {
        return new PageInfo<>(results, totalCount, pageNum, pageSize);
    }

}
